home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Overview / Sample / Sample.inc1.a < prev    next >
Encoding:
Text File  |  1994-11-18  |  11.9 KB  |  314 lines  |  [TEXT/MPS ]

  1. *
  2. *    Apple Macintosh Developer Technical Support
  3. *
  4. *    MultiFinder-Aware Simple Sample Application
  5. *
  6. *    Sample
  7. *
  8. *    Sample.inc1.a    -    Assembler Source
  9. *
  10. *    Copyright © 1989 Apple Computer, Inc.
  11. *    All rights reserved.
  12. *
  13. *    Versions:    
  14. *        1.00            08/88
  15. *        1.01            11/88
  16. *        1.02            04/89
  17. *        1.03            06/89
  18. *        1.04            06/92
  19. *
  20. *    Components:
  21. *        Sample.p        June 1, 1989
  22. *        Sample.c        June 1, 1989
  23. *        SampleInit.c        June 2, 1992
  24. *        Sample.a        June 1, 1989
  25. *        Sample.inc1.a        June 1, 1989
  26. *        SampleMisc.a        June 1, 1989
  27. *        Sample.r        June 1, 1989
  28. *        Sample.h        June 1, 1989
  29. *        PSample.make        June 1, 1989
  30. *        CSample.make        June 1, 1989
  31. *        ASample.make        June 1, 1989
  32. *        CSample.π        June 2, 1992
  33. *        CSample.π.rsrc        June 2, 1992
  34. *
  35. *    Sample is an example application that demonstrates how to
  36. *    initialize the commonly used toolbox managers, operate 
  37. *    successfully under MultiFinder, handle desk accessories, 
  38. *    and create, grow, and zoom windows.
  39. *
  40. *    It does not by any means demonstrate all the techniques 
  41. *    you need for a large application. In particular, Sample 
  42. *    does not cover exception handling, multiple windows/documents, 
  43. *    sophisticated memory management, printing, or undo. All of 
  44. *    these are vital parts of a normal full-sized application.
  45. *
  46. *    This application is an example of the form of a Macintosh 
  47. *    application; it is NOT a template. It is NOT intended to be 
  48. *    used as a foundation for the next world-class, best-selling, 
  49. *    600K application. A stick figure drawing of the human body may 
  50. *    be a good example of the form for a painting, but that does not 
  51. *    mean it should be used as the basis for the next Mona Lisa.
  52. *
  53. *    We recommend that you review this program or TESample before 
  54. *    beginning a new application.
  55.  
  56. * ----------- DEBUGGING INFORMATION -------------
  57. * This is used as a global switch to turn off the generation of debugging information.
  58. * The MACRO "DbgInfo" will generate this debugging information if set to 1.
  59.  
  60. DebuggerInfo    EQU    1
  61.  
  62.  
  63. * ================================================
  64. * --------   MACRO DEFINITIONS SECTION  ----------
  65. * ================================================
  66.  
  67. * ------------- GENERATE A PASCAL "CASE" OR "IF" SEQUENCE -------------
  68. * The following macro is used to generate a branch based on an index value
  69. * in a D-register with a value from 0 to N.  The branch is through a table
  70. * of relative addresses also generated by this macro. The macro is called
  71. * in one of two forms as follows:
  72.  
  73. *  {Form #1}    Case#        (Dreg,Default),case0,case1,...caseN
  74. *  {Form #2}    Case#.<size>    (Dreg,IF),(cst0,case0),...,(cstN,caseN)
  75.  
  76. * In Form #1, the "Default" specifies a label for any omitted case labels not
  77. * specified explicitly. The "case0", "case1",..."caseN" are case labels
  78. * identifying the various cases to be processed.  A case label may be omitted,
  79. * in which case the "Default" is used. The "Default" may also be omitted, but
  80. * in that case all case labels must be specified. If there are fewer case labels
  81. * than there are cases, but there are N possible values for the case index, the
  82. * proper number of trailing commas must be supplied to generate the defaults.
  83.  
  84. * In Form #2, the default is specified as the word "IF".  In this form the macro
  85. * generates a set of compares (CMPI's) and branches (BEQ) for each specified
  86. * case (there is no implicit default).    Each case is a constant/label pair.
  87. * The constant is compared (CMPI.W) and an branch is done (BEQ) to the case if
  88. * the Dreg equals the constant.  A size may be specified for all the branches
  89. * as a <size> attribute to the Case# call itself.  This must either be an "S"
  90. * or "W" to generate BEQ.S's or BEQ.W's.  The default is for "S".
  91.  
  92.         MACRO
  93.         Case#.&Size     &IdxDef
  94.         PRINT        Push,NoMDir     ; only list generated code
  95.         LCLA        &i        ; index to macro parameters
  96.         LCLA        &n        ; total number of macro parameters
  97.         LCLC        &Dreg,&Def    ; the Dreg and Default parameters
  98.         LCLC        &sz         ; the <size> value
  99.  
  100. &Dreg        SETC        &IdxDef[1]    ; pick off 1st opnd of sublist
  101. &Def        SETC        &IdxDef[2]    ; pick off 2nd opnd of sublist
  102. &n        SETA        &Nbr(&Syslist)    ; done for efficiency
  103. &i        SETA        2        ; cases start at 2nd parameter
  104.  
  105.  IF &UpCase(&Def) <> 'IF' THEN
  106. .* Create the jump table and the index value
  107. * -----------------------------------------------
  108.     ADD         &Dreg,&Dreg
  109.     MOVE        Case&SysNdx(&Dreg),&Dreg
  110.     JMP         Case&SysNdx(&Dreg)
  111.  
  112. Case&SysNdx
  113.     WHILE &i <= &n DO                ; process each case label
  114.        IF &SysList[&i] <> '' THEN
  115.         DC.W        &SysList[&i]-Case&SysNdx
  116.        ELSE
  117.         DC.W        &Def-Case&SysNdx
  118.        ENDIF
  119.        &i: SETA &i+1                 ; count off parameter
  120.     ENDWHILE
  121.  ELSE                            ; process (Cst,lbl) pairs
  122.  
  123. .* Create a series of CMPI and BEQ instructions
  124. * -----------------------------------------------
  125.     &Sz: SETC &Default(&Size, 'S')             ; setup size attribute
  126.     WHILE &i <= &n DO                ; process each (Cst,lbl) pair
  127.        CMPI        #&SysList[&i,1],&Dreg
  128.        BEQ.&Sz     &SysList[&i,2]
  129.        &i: SETA &i+1                ; count off parameter
  130.     ENDWHILE
  131.  ENDIF
  132.  
  133.         PRINT    Pop                 ; restore original print status
  134.         ENDM
  135.  
  136.  
  137. * ------------- GENERATE DEBUGGER SYMBOL INFORMATION -------------
  138. * This Macro will generate information for the debugger to read and display
  139. * as its module name.  This aids in debugging Asm code while looking at it
  140. * in the debugger.  This macro can only work if called at the end of stack
  141. * frame.  The appearance of the Macro statement in the source code must occur
  142. * immediately after the final "JMP   (A0)" or "RTS" instruction following the UNLINK.
  143. * Spaces may be included in the name, but no quotes are allowed.
  144.  
  145. *  {Form #1}    DbgInfo        ModName
  146. *  {Form #2}    DbgInfo.New    Really Long Module Name For MacsBug 6.0
  147.  
  148. * There are now two naming conventions used in MacsBug, Form #1 is the older MacsBug,
  149. * or TMON, and Form #2 is the newer MacsBug 6.0.  The older method would only
  150. * allow for a fixed length of eight characters.  If a shorter name is passed to
  151. * this Macro, it will extend the length to 8 chars with trailing spaces.
  152. * MacsBug 6.0 will now allow for a variable length C type string. This Macro will
  153. * create the proper DC statements and takes into account word alignment issues.
  154.  
  155.  
  156.         MACRO
  157.         DbgInfo.&Opt     &ModName#    ; the name to be used in the Debugger
  158.         PRINT        Push,NoMDir     ; Only list generated code
  159.         LCLC        &DbgName#    ; name to generate for MacsBug
  160.         LCLC        &DbgTemp    ; temporary name variable
  161.         LCLC        &New        ; variable used to test old vs. new
  162.         LCLC        &S        ; variable used to save PRINT state
  163.  
  164.  IF DebuggerInfo THEN                        ; do we want debugging info?
  165.     IF &ModName# ≠ '' THEN                    ; did we get a module name?
  166.     &New: SETC &UpCase(&Opt)                ; make option all upper case
  167.     IF (&New = 'NEW') THEN                    ; do we want new style?
  168.  
  169. .* Create the new MacsBug naming convention
  170. * -----------------------------------------------
  171.        &DbgTemp: SETC    &ModName#            ; generate new type symbols
  172.        IF &Len(&ModName#) < 32 THEN                ; if module name < 32 chars
  173.         IF &Len(&ModName#) // 2 = 0 THEN         ; add space if even so that...
  174.            &DbgTemp: SETC &Concat(&ModName#,' ')     ; string length plus length byte...
  175.         ENDIF                        ; will align to word boundary
  176.        &DbgName#: SETC &Concat(&Chr($80 + &Len(&ModName#)), &DbgTemp)
  177.        ELSE                            ; Length > 32 characters
  178.         IF &Len(&ModName#) // 2 = 1 THEN         ; add space if length is odd
  179.            &DbgTemp: SETC &Concat(&ModName#,' ')
  180.         ENDIF
  181.        &DbgName#: SETC &Concat(&Chr($80), &Chr(&Len(&ModName#)), &DbgTemp)
  182.        ENDIF
  183.     ELSE                            ; make it the older style
  184.  
  185. .* Create the older MacsBug naming convention
  186. * -----------------------------------------------
  187.        IF &Len(&ModName#) < 8 THEN                ; if module name < 8 chars
  188.         &DbgName#: SETC &Concat(&ModName#,'       ')    ; add at least 7 spaces
  189.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&DbgName#,1,1))), &SubStr(&DbgName#,2,7))
  190.        ELSE                            ; there are at least 8 chars
  191.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&ModName#,1,1))), &SubStr(&ModName#,2,7))
  192.        ENDIF
  193.     ENDIF
  194.  
  195. .* Create the DC.B with the debugger name, and include the NULs if new MacsBug option
  196. * -----------------------------------------------
  197.     &S: SETC &Setting('STRING')        ; preserve STRING status
  198.     IF &S ≠ 'ASIS' THEN            ; only change it if not already ASIS
  199.        STRING    ASIS
  200.        DC.B      '&DbgName#'
  201.        IF (&New = 'NEW') THEN
  202.         DC.W        0        ; fake literal size for new MacsBug
  203.        ENDIF
  204.        STRING    &S
  205.     ELSE
  206.        DC.B      '&DbgName#'
  207.        IF (&New = 'NEW') THEN
  208.         DC.W        0        ; fake literal size for new MacsBug
  209.        ENDIF
  210.     ENDIF
  211.    ENDIF
  212.  ENDIF
  213.  
  214.         PRINT    Pop             ; restore original print status
  215.         ENDM
  216.  
  217.  
  218. * ================================================
  219. * ---------------  EQUATE SECTION  ---------------
  220. * ================================================
  221.  
  222. * Some various EQUATES we'll use throughout the program.
  223. * -----------------------------------------------
  224. NIL        EQU    0        ; a NIL pointer to test against
  225.  
  226. ToolTrapBit    EQU    11        ; this bit is on for Tool traps
  227. WaitNextEvent    EQU    $A860        ; the WaitNextEvent trap number
  228. Unimplemented    EQU    $A89F        ; the Unimplemented trap number
  229. EnvironsVersion    EQU    1        ; this is the version of the SysEnvirons we want
  230. SleepValue    EQU    $7FFFFFFF    ; the sleeping time ($7FFFFFFF = MaxLongInt)
  231. SuspendResume    EQU    1        ; the suspend/resume event number of an OSEvent
  232. NoEvents    EQU    0        ; no events mask
  233. ExtremeNeg    EQU    -32768        ; for wide open rects and regions, see AdjustCursor
  234. ExtremePos    EQU    32767-1        ; -1 is because of a bug in regions, see AdjustCursor
  235.  
  236. * This is the minimum result from the following equation:
  237.  
  238. *    applLimit - applZone = minimum heap size
  239.  
  240. * for the application to run. It will insure that enough memory will
  241. * be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  242. * application, and still give the application some 'breathing room'.
  243. * To derive this number, we ran under a MultiFinder partition that was
  244. * our requested minimum size, as given in the 'SIZE' resource.
  245.  
  246. MinHeap        EQU    21*1024        ; minimum heap size in bytes
  247.  
  248. * This is the minimum exceptable result from PurgeSpace, when called
  249. * at initialization time, for the application to run. This number acts
  250. * as a double-check to insure that there really is enough memory for the
  251. * application to run, including what has been taken up already by
  252. * pre-loaded resources, the scrap, code, and other sundry memory blocks.
  253.  
  254. MinSpace    EQU    8*1024        ; minimum stack space in bytes
  255.  
  256.  
  257. * The following equates use for resources.  That's why they have a "r" in front.
  258. * -----------------------------------------------
  259. rMenuBar    EQU    128        ; application's menu bar
  260. rUserAlert    EQU    129        ; error alert for user
  261. rWindow        EQU    128        ; application's window
  262. rAboutAlert    EQU    128        ; about alert
  263. rStopRect    EQU    128        ; rectangle for Stop light
  264. rGoRect        EQU    129        ; rectangle for Go light
  265.  
  266.  
  267. * The following equates are for menu definitions, obviously.
  268. * -----------------------------------------------
  269. AppleMenu    EQU    128        ;  Apple menu
  270. AboutItem    EQU    1
  271.  
  272. FileMenu    EQU    129        ;  File menu
  273. NewItem        EQU    1
  274. OpenItem    EQU    2
  275. CloseItem    EQU    4
  276. SaveItem    EQU    5
  277. SaveAsItem    EQU    6
  278. RevertItem    EQU    7
  279. PageSetupItem    EQU    9
  280. PrintItem    EQU    10
  281. QuitItem    EQU    12
  282.  
  283. EditMenu    EQU    130        ;  Edit menu
  284. UndoItem    EQU    1
  285. CutItem        EQU    3
  286. CopyItem    EQU    4
  287. PasteItem    EQU    5
  288. ClearItem    EQU    6
  289.  
  290. LightMenu    EQU    131        ;  Light menu
  291. StopItem    EQU    1
  292. GoItem        EQU    2
  293.  
  294. * -----------------------------------------------
  295. DITopLeft    EQU    $00500070    ; position of Disk Init dialogs
  296.  
  297. * ------------- ALL OF OUR GLOBAL DATA -------------
  298. * Note the minimal amount of globals we're using.  Data such as
  299. * the EventRecord, WindowRecords, etc. do not belong in global data
  300. * allocation.  Only data that basically doesn't change through out the
  301. * execution of the program is considered global.  The boolean flags are
  302. * global, since they affect the state of the program at any given time.
  303. * Also note that any appearance of a DS outside of a stack frame will
  304. * be allocated off of A5 and becomes part of global data storage.
  305.  
  306. AppGlobals    RECORD    0        ; this is our global data storage
  307. Stopped        DS.W    1        ; boolean for the state of the light
  308. HasWNEvent    DS.W    1        ; boolean for WaitNextEvent trap, see ForceEnvirons
  309. InBackground    DS.W    1        ; boolean for if in background, see OSEvent
  310. StopRect    DS    Rect        ; rect for the Stop light, set from a resource
  311. GoRect        DS    Rect        ; rect for the Go light, set from a resource
  312. Mac        DS    SysEnvRec    ; the system environment record, see ForceEnvirons
  313.           ENDR
  314.